//
//  SetPasswordViewController.m
//  PigMarket
//
//  Created by mac on 2019/3/15.
//  Copyright © 2019 felix.pigmarket.oc. All rights reserved.
//

#import "SetPasswordViewController.h"

@interface SetPasswordViewController ()
/**
 提示label
 */
@property (nonatomic , strong) UILabel *reminderLab;

/**
 输入框背景
 */
@property (nonatomic , strong) UIView *inputBgView;

/**
 密码输入框
 */
@property (nonatomic , strong) UITextField *passwordField;

/**
 
 */
@property (nonatomic , strong) UIButton *passwordSecurityBtn;

/**
 
 */
@property (nonatomic , strong) UIButton *confirmPasswordSecutityBtn;
/**
 确认密码输入框
 */
@property (nonatomic , strong) UITextField *confirmPasswordField;

/**
 灰线
 */
@property (nonatomic , strong) UIView *lineView;

/**
 保存Btn
 */
@property (nonatomic , strong) UIButton *saveBtn;
@end

@implementation SetPasswordViewController

#pragma mark - view life cycle
- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"设置密码";
    [self setUpView];
}

-(void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
}

-(void)viewDidDisappear:(BOOL)animated {
    [super viewDidDisappear:animated];
}

#pragma mark - init method
- (void)setUpView {
    [self initView];
    [self initLayout];
    [self initAction];
    [self initData];
}
- (void)initView {
    [self.view addSubview:self.reminderLab];
    [self.view addSubview:self.inputBgView];
    [self.inputBgView addSubview:self.lineView];
    [self.inputBgView addSubview:self.passwordField];
    [self.inputBgView addSubview:self.confirmPasswordField];
    [self.view addSubview:self.saveBtn];
    [self.inputBgView addSubview:self.passwordSecurityBtn];
    [self.inputBgView addSubview:self.confirmPasswordSecutityBtn];

}

- (void) initLayout {
    [self.reminderLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(6);
        make.left.mas_equalTo(20);
        make.width.mas_equalTo(SCREEN_WIDTH - 40);
    }];
    [self.inputBgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(0);
        make.top.mas_equalTo(self.reminderLab.mas_bottom).offset(6);
        make.height.mas_equalTo(109);
    }];
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.left.mas_equalTo(0);
        make.centerY.mas_equalTo(self.inputBgView.mas_centerY);
        make.height.mas_equalTo(1);
    }];
    [self.passwordField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(20);
        make.top.mas_equalTo(0);
        make.bottom.mas_equalTo(self.lineView.mas_top);
        make.right.mas_equalTo(-40);
    }];
    
    [self.confirmPasswordField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(20);
        make.top.mas_equalTo(self.lineView.mas_bottom);
        make.bottom.mas_equalTo(self.inputBgView.mas_bottom);
        make.right.mas_equalTo(-40);
    }];
    [self.saveBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(20);
        make.top.mas_equalTo(self.inputBgView.mas_bottom).offset(60);
        make.right.mas_equalTo(-20);
        make.height.mas_equalTo(48);
    }];
    [self.passwordSecurityBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-20);
        make.centerY.mas_equalTo(self.passwordField.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(20, 20));
    }];
    [self.confirmPasswordSecutityBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-20);
        make.centerY.mas_equalTo(self.confirmPasswordField.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(20, 20));
    }];
    
}

- (void) initAction {
    [self.passwordSecurityBtn addTarget:self action:@selector(passwordSecurityClick) forControlEvents:UIControlEventTouchUpInside];
    [self.confirmPasswordSecutityBtn addTarget:self action:@selector(confirmPasswordSecurityClick) forControlEvents:UIControlEventTouchUpInside];

}

- (void)initData {
    
}

#pragma mark - delegate

#pragma mark - target action
- (void)passwordSecurityClick {

    self.passwordField.secureTextEntry = !self.passwordField.secureTextEntry;
    self.passwordSecurityBtn.selected = !self.passwordSecurityBtn.selected;
}
- (void)confirmPasswordSecurityClick {
    self.confirmPasswordField.secureTextEntry = !self.confirmPasswordField.secureTextEntry;

    self.confirmPasswordSecutityBtn.selected = !self.confirmPasswordSecutityBtn.selected;

}
#pragma mark - private method

#pragma mark - getter and setter
- (UILabel *)reminderLab {
    if (!_reminderLab) {
        _reminderLab = [[UILabel alloc] init];
        _reminderLab.textColor = [UIColor tipsGrayColor];
        _reminderLab.font = [UIFont middleFont];
        _reminderLab.text = @"密码只支持数字，字母及下划线，6-16个字符";
    }
    return _reminderLab;
}
- (UIView *)inputBgView {
    if (!_inputBgView) {
        _inputBgView = [[UIView alloc] init];
        _inputBgView.backgroundColor = [UIColor whiteColor];
    }
    return _inputBgView;
}
- (UITextField *)passwordField {
    if (!_passwordField) {
        _passwordField = [[UITextField alloc] init];
        _passwordField.placeholder = @"请输入密码";
        _passwordField.secureTextEntry = YES;
    }
    return _passwordField;
}
- (UITextField *)confirmPasswordField {
    if (!_confirmPasswordField) {
        _confirmPasswordField = [[UITextField alloc] init];
        _confirmPasswordField.placeholder = @"请再次输入密码";
        _confirmPasswordField.secureTextEntry = YES;
    }
    return _confirmPasswordField;
}
- (UIView *)lineView {
    if (!_lineView) {
        _lineView = [[UIView alloc] init];
        _lineView.backgroundColor = [UIColor colorWithHexString:@"#000000" alpha:0.08];
    }
    return _lineView;
}
- (UIButton *)saveBtn {
    if (!_saveBtn) {
        _saveBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_saveBtn setTitle:@"保存" forState:UIControlStateNormal];
        [_saveBtn setBackgroundImage:[UIImage imageNamed:@"btn_nomal_bg"] forState:UIControlStateNormal];
    }
    return _saveBtn;
}
- (UIButton *)passwordSecurityBtn {
    if (!_passwordSecurityBtn) {
        _passwordSecurityBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_passwordSecurityBtn setImage:[UIImage imageNamed:@"login_hidden"] forState:UIControlStateNormal];
        [_passwordSecurityBtn setImage:[UIImage imageNamed:@"login_show"] forState:UIControlStateSelected];
    }
    return _passwordSecurityBtn;
}
- (UIButton *)confirmPasswordSecutityBtn {
    if (!_confirmPasswordSecutityBtn) {
        _confirmPasswordSecutityBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_confirmPasswordSecutityBtn setImage:[UIImage imageNamed:@"login_show"] forState:UIControlStateSelected];
        [_confirmPasswordSecutityBtn setImage:[UIImage imageNamed:@"login_hidden"] forState:UIControlStateNormal];

    }
    return _confirmPasswordSecutityBtn;
}
@end

